var roleManage = function() {

    var _init = function() {

        var table = $('#table_role');

        var tableUnit=table.dataTable({
            "processing": true,
            // 开启服务器模式
            serverSide: true,
            "ajax": {
            	url:"/a/calc/tenLogs",
            },
            "autoWidth": true,
            "columns": [{
                    "data": "name"
                },
                {
                    "data": "createName"
                },
                {
                    "data": "ip"
                },
                {
                    "data": "createDate",
                    "render": function(data, type, row, meta) {
                        return moment(data).format('YYYY-MM-DD HH:mm');
                    }
                }
              
            ],
            "language": {
                "lengthMenu": "每页显示 _MENU_ 条记录",
                "emptyTable": "暂无数据记录",
                "info": "显示 _START_ 至 _END_ 条数据，共 _TOTAL_ 条记录！",
                "zeroRecords": "没有搜索到匹配记录",
                "infoEmpty": "",
                "infoFiltered": "",
                "processing": "数据加载中,请稍后..."

            },
            "pageLength": 10,
            "order": [
                [3, "desc"]
            ],
        	"sort": false,
            "columnDefs": [{
                "orderable": false,
                "targets": [0, 3]
            } ],
            "dom": "<'row'<'.col-md-6 col-sm-12'><'col-md-6 col-sm-12'>r>" +
                "<t>" +
                "<'row'<'col-md-5'i><'col-md-7'>p>",
            "fnInitComplete": function() {},
            "fnDrawCallback": function(){
          	/*　　var api = this.api();
          	　　var startIndex= api.context[0]._iDisplayStart;//获取到本页开始的条数
          	　　api.column(0).nodes().each(function(cell, i) {
          	　　　　cell.innerHTML = startIndex + i + 1;
          	　　}); */
          	}
        });


        
       

        

     
    }

    return {
        init: function() {
            _init();
        }

    };

}();


$('#doQuery').click(function(event){
	  var template =   $("#search select[name='template']").val();

	  var createName =   $("#search input[name='createName']").val();
	  var name =   $("#search select[name='name']").val();
	  var start =   $(" input[name='start']").val();
	  var end =   $(" input[name='end']").val();
	  var param={"createName":createName,"createDate":start,"updateDate":end,"name":name,"template":template};
	  $('#table_role').DataTable().search(JSON.stringify(param)  ).draw();
	});
  
	

$("#search select[name='template']").change(function() {
	 var template =   $("#search select[name='template']").val();
    
	$.ajax({
		url : '/a/calc/getActions?templateName='+template,
		dataType : 'json',
		contentType:"application/json; charset=utf-8",
		 async: false,
//		data : JSON.stringify({ template: templateId }),
	}).done(function(data) {
		if (data.status === '1') {
			 $('.category').html("<option value=''>全部</option>");
				for (var i = 0; i < data.data.length; i++) {
			        $('.category').append("<option value='"+data.data[i]+"'>" + data.data[i] + "</option>");
			      }
			
		} else if (data.status === '2') {
		}
	});
	return false;
  });


$(function() {
    roleManage.init();

});